package com.ohuang.test_compose.page

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.ohuang.test_compose.MainViewModel
import com.ohuang.test_compose.composeView.PageNavHost
import com.ohuang.test_compose.composeView.PageNavHostController

@OptIn(
    ExperimentalPermissionsApi::class,
    androidx.compose.runtime.InternalComposeApi::class,
    com.google.accompanist.pager.ExperimentalPagerApi::class,
    androidx.compose.ui.unit.ExperimentalUnitApi::class,
    androidx.compose.material.ExperimentalMaterialApi::class,
    androidx.compose.animation.ExperimentalAnimationApi::class
)
@Composable
fun PageNavHostPage() {
    val vm: MainViewModel = viewModel()

    Box() {

        val controller = rememberSaveable() {
            PageNavHostController()
        }
        PageNavHost(controller = controller, defaultKey = "CanvasPage") {
            add("CanvasPage") { CanvasPage() }
            add("ImagePage") { ImagePage() }
            add("TextPage") { TextPage() }
        }
        var state by remember {
            mutableStateOf(true)
        }
        if (state) {
            LazyColumn(modifier = Modifier.height(200.dp)) {
                item {
                    Button(onClick = {
                        state = false
                    }) {
                        Text(text = "隐藏")
                    }
                }
                item {
                    Button(onClick = { vm.pageSliceManager.finishToStart { PageNavHostPage() } }) {
                        Text(text = "finishToStart{PageNavHostPage()}")
                    }
                }
                item {
                    Button(onClick = { controller.navigation("CanvasPage") }) {
                        Text(text = "CanvasPage")
                    }
                }
                item {
                    Button(onClick = { controller.navigation("ImagePage") }) {
                        Text(text = "ImagePage")
                    }
                }
                item {
                    Button(onClick = { controller.navigation("TextPage") }) {
                        Text(text = "TextPage")
                    }
                }
            }
        } else {
            Button(onClick = {
                state = true
            }) {
                Text(text = "显示")
            }
        }
    }
}